import Vue from 'vue';
import Vuex from 'vuex'
// TODO: vue3 store 的用法需要兼容

Vue.use(Vuex);


export default new Vuex.Store({
    state: {
        topListIds: [],
        nextId: '',
    },
    mutations: {
        INIT_TOPLIST_IDX(state, payload) {
            state.topListIds = payload;
        },
        NEXT_ID(state, payload) {
            const len = state.topListIds.length;
            
            if (!len) {
                return;
            }
            
            const list = state.topListIds;
            for (let i = 0; i < len; i++) {
                if (i === len -1) {
                    return;
                }
                if (Number(payload) === list[i].id) {
                    state.nextId = list[i + 1].id
                    break;
                }
            }
        }
    }
})